<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>患者档案</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <link rel="stylesheet" href="../../lib/layui/css/layui.css">
    <script src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>

</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>

            <a>
              <cite>患者档案/Patient records</cite></a>
          </span>
                        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
                           onclick="location.reload()" title="刷新">
                            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
                    </div>
                    </br>
                    <form class="layui-form layui-col-space5" autocomplete="off">
                        <div class="layui-input-inline">
                            <input type="text" name="p_name" required lay-verify="p_name" placeholder="患者姓名"
                                   autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="p_phone" required lay-verify="p_phone" placeholder="患者电话"
                                   autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <a class="layui-btn" lay-submit="" lay-filter="searche_btn" id="searche_btn"><i
                                    class="layui-icon">&#xe615;</i></a>
                        </div>
                    </form>
                </div>
                <!-- 表格  -->
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-hide" id="test" lay-filter="test"></table>
                </div>


            </div>
        </div>
    </div>
</div>
</div>
</div>

</body>
</html>

<!-- 操作栏  -->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script>
    $(function () {
        loadpage();
    })

    function loadpage() {

        params = {"p_name": $("[name='p_name']").val(), "p_phone": $("[name='p_phone']").val()};
        renderdata(params);
    }

    function useAjax(url, type, dataType, data, $success) {
        var load; //加载等待图标的组件
        $.ajax({
            url: url,
            type: type,
            data: data,
            dataType: dataType,
            before: function () {
                load = layer.load();
            },
            success: $success,
            complete: function () {
                layer.close(load);
            },
            error: function (jqxhr) {
                layer.msg(jqxhr.status);
            }
        });
    }

    function renderdata(param) {
        useAjax("/JT90/getRecordslist", "get", "json", param, function (res) {
            var data = res.result;

            render(data);
        })
    }

    function render(data) {
        layui.use(['table', 'laydate', 'layer', 'form', 'laypage'], function () {
            var table = layui.table,
                layer = layui.layer,
                form = layui.form,
                laypage = layui.laypage;
            laydate = layui.laydate;
            //日期范围
            laydate.render({
                elem: '#test6'
                , range: true
            });
            table.render({
                elem: '#test'
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , data: data
                , title: '患者信息'
                , cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'p_id', title: '患者ID'}
                    , {field: 'p_name', title: '姓名'}
                    , {field: 'p_gender', title: '性别'}
                    , {field: 'p_age', title: '年龄'}
                    , {field: 'p_phone', title: '手机号码'}
                    , {field: 'p_allergy', title: '有无过敏史'}
                    , {field: 'p_chronic', title: '有无慢性病'}
                    , {field: 'id_card', title: '身份证号码'}
                    , {field: 'create_date', title: '建档日期'}
                    , {fixed: 'right', title: '操作', width: '13%',toolbar: '#barDemo'}
                ]]
                , response: {
                    dataName: 'result' //规定数据列表的字段名称，默认：data   表示这是要解析的参数
                }
                , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'] //自定义分页布局
                    , groups: 5 //只显示 1 个连续页码
                    , first: false //不显示首页
                    , last: false //不显示尾页
                    , limit: 5
                    , limits: [5, 10, 15, 20]
                    , theme: '#44cc33'
                }

            });


            //监听行工具事件
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                var layEvent = obj.event;
                //console.log(obj)
                if (obj.event === 'del') {
                    layer.confirm('确定要删除档案吗?', function (index) {
                        useAjax("/JT90/delRecords", "GET", "JSON", {p_id: data.p_id},
                            function (map) {
                                if (map.success) {
                                    parent.layer.msg("删除成功!",{time:1500,icon: 6}, function () {
                                        //重新加载父页面
                                        location.reload();
                                    });
                                    return;
                                } else {
                                    layer.msg("删除失败", {icon: 5});
                                }
                            },
                            function (jqxhr) {
                                layer.msg(jqxhr.status);
                            }
                        )
                    });
                } else if (obj.event === 'edit') {
                    var data = obj.data; //获得当前行数据
                    /* var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）*/
                    var p_id = data.p_id;//获取选中行的对象的id值
                    var p_name = data.p_name;
                    var p_gender = data.p_gender;
                    var p_age=data.p_age;
                    var p_phone=data.p_phone;
                    var p_allergy=data.p_allergy;
                    var p_chronic=data.p_chronic;
                    var id_card=data.id_card;
                    console.log(p_id + "--" + p_name);
                    //编辑弹窗事件
                    layer.open({
                        type: 2,
                        area: ['600px', '400px'],
                        title: '修改档案',
                        content: 'http://122.51.140.205:8892/JT90/index/1Registered/1.2edit.html?p_id=' + p_id + '&p_name=' + p_name+ '&p_gender=' + p_gender+'&p_age='+p_age+'&p_phone='+p_phone+'&p_allergy='+p_allergy+'&p_chronic='+p_chronic+'&id_card='+id_card,
                        success: function () {
                            var body = layer.getChildFrame('body');//获取弹窗页面
                            body.find('#p_id').val(p_id);
                            body.find('#p_name').val(p_name);
                            body.find('#p_gender').val(p_gender);
                            body.find('#p_age').val(p_age);
                            body.find('#p_phone').val(p_phone);
                            body.find('#p_allergy').val(p_allergy);
                            body.find('#p_chronic').val(p_chronic);
                            body.find('#id_card').val(id_card);
                        }

                    });

                }
            });
        });
    }



    //监听提交
    $("#searche_btn").click(function () {
        loadpage();
    });






</script>

